package org.autoparser.filters;

import java.util.regex.Pattern;

import org.htmlparser.Attribute;
import org.htmlparser.Node;
import org.htmlparser.Tag;
import org.htmlparser.filters.HasAttributeFilter;

@SuppressWarnings("serial")
public class HasAttUsRegexFilter extends HasAttributeFilter {

	private Pattern pat;
	public HasAttUsRegexFilter(String attName, String attValue) {
		super(attName,attValue);
		pat = Pattern.compile(mValue,Pattern.CASE_INSENSITIVE);
	}

	@Override
	public boolean accept(Node node) {
		// TODO Auto-generated method stub
		Tag tag;
        Attribute attribute;
        boolean ret;

        ret = false;
        if (node instanceof Tag){
            tag = (Tag)node;
            attribute = tag.getAttributeEx (mAttribute);
            ret = null != attribute;
            if (ret && (null != mValue)){
                ret = pat.matcher(attribute.getValue()).find();
            }
        }
        return (ret);
	}
}
